import { createSlice } from '@reduxjs/toolkit';
import * as THREE from 'three'

export interface IEditorSelectMeshData {
  mesh: THREE.Object3D | null;
}

export interface IReduceRotate {
  payload: THREE.Vector3,
  type: string
}

const initialState: IEditorSelectMeshData = {
  mesh: new THREE.Object3D(),
};

// 创建一个 Slice
export const editorSelectMeshData = createSlice({
  // 命名空间
  name: 'editorSelectMeshData',

  // 初始化状态值
  initialState,

  reducers: {
    setMesh(state, { payload }) {
      state.mesh = payload.mesh;
    },
    setRotate(state, reduce: IReduceRotate) {
      state.mesh?.rotation.set(reduce.payload.x, reduce.payload.y, reduce.payload.z);
    },
  },
});

// 导出 reducers 方法
export const { setMesh, setRotate } = editorSelectMeshData.actions;

// 默认导出
export default editorSelectMeshData.reducer;